package com.leetcode;

/**
 * 相交链表
 *
 * @author winson
 * @create 2022-04-11 10:16
 */
public class IntersectionNodeSolution {

    public ListNode getIntersectionNode(ListNode headA, ListNode headB) {
        if (headA == null || headB == null) {
            return null;
        }
        /**
         * 双向指针
         */
        ListNode pa = headA, pb = headB;
        while (pa != pb) {
            pa = pa == null ? headB : pa.next;
            pb = pb == null ? headA : pb.next;
        }
        return pa;
    }
}
